import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;

public class Reserve
{
	public static int reserveid = 0;
	public static int facilityid = 0;
	public static Date reservedate = null;
	public static boolean new_record = false;

	public Reserve(int fid, Date rd)
	{
		new_record = true;
		facilityid = fid;
		reservedate = rd;
	}

	public Reserve(int rid) throws SQLException
	{
		new_record = false;
		reserveid = rid;

		Connector conn = new Connector("select * from reserve where reserveid = '" + rid + "'");
		ResultSet rs = conn.execute();
		if(rs.first())
		{
			facilityid = rs.getInt("facilityid");
			String rd = rs.getString("reservedate");
			try
			{
				DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
				reservedate = format.parse(rd);
			}
			catch (ParseException e)
			{
				e.printStackTrace();
			}
		}
		rs.close();
	}
	
	public static boolean insert() throws SQLException
	{
		if(new_record)
		{
			Timestamp trd = new Timestamp(reservedate.getTime());
			
			String sql = "insert into reserve values(null,"
						+ facilityid + ",'"
						+ trd + "')";

			Connector conn = new Connector(sql);
			conn.execute_sql();
			
			return true;
		}
		else
			return false;
	}

	public static boolean delete() throws SQLException
	{
		if(!new_record)
		{
			String sql = "delete from reserve where reserveid='" + reserveid + "'";

			Connector conn = new Connector(sql);
			conn.execute_sql();
			
			return true;
		}
		else
			return false;
	}

	public static void setReserveId(int rid)
	{
		reserveid = rid;
	}

	public static void setFacilityId(int fid)
	{
		facilityid = fid;
	}

	public static void setReserveDate(Date rd)
	{
		reservedate = rd;
	}

	public static int getReserveId()
	{
		return reserveid;
	}

	public static int getFacilityId()
	{
		return facilityid;
	}

	public static Date getReserveDate()
	{
		return reservedate;
	}
}
